package com.ruoyi.service.score.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.score.entity.LaborScoreEntity;
import com.ruoyi.service.score.mapper.LaborScoreMapper;
import com.ruoyi.service.score.service.LaborScoreService;
import com.ruoyi.service.user.entity.UserEntity;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户评分表 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-14
 */
@Service
public class LaborScoreServiceImpl extends ServiceImpl<LaborScoreMapper, LaborScoreEntity>
    implements LaborScoreService {

  @Override
  public void initLaborScore(UserEntity userEntity) {
    LaborScoreEntity laborScoreEntity = new LaborScoreEntity()
        .setAvgScore(0)
        .setLaborId(userEntity.getUserId())
        .setCreateBy(userEntity.getUserId())
        .setCreateTime(LocalDateTime.now())
        .setUpdateBy(userEntity.getUserId())
        .setUpdateTime(LocalDateTime.now());
    save(laborScoreEntity);
  }

  @Override
  public LaborScoreEntity getByLaborId(Long laborId) {
    return getOne(getWrapper().eq(LaborScoreEntity::getLaborId, laborId));
  }

  @Override
  public List<LaborScoreEntity> listByLaborIds(List<Long> userIds) {
    return list(getWrapper().in(LaborScoreEntity::getLaborId, userIds));
  }

  private LambdaQueryWrapper<LaborScoreEntity> getWrapper() {
    return new LambdaQueryWrapper<>();
  }
}
